package com.mohan.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mohan.pojo.Article;
import com.mohan.pojo.User;
import com.mohan.rep.LoginRep;
import com.mohan.service.LoginService;
import com.mohan.service.ArticleService;
import com.mohan.util.ResponseUtil;

@RequestMapping(value = "/V1/mohan")
@Controller
public class MoHanController {
	@Resource
	private ArticleService articleService;
	@Resource
	private LoginService loginService;
	
	@RequestMapping("/search")
	@ResponseBody
	public Object searchArticles(HttpServletRequest request,
			@RequestParam(value="req") String req,
			@RequestParam(value="type") String type,
			@RequestParam(value="token") String token,
			@RequestParam(value="userid") String userid
			){
		
		System.out.println("req is :\n" + req);
		
		ResponseUtil response = new ResponseUtil();
		List<Article> articles;
		try {
			articles = this.articleService.getArticles();
			response.defaultSucess(articles);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
		return response;	
	}
	
	@RequestMapping("/test")
	@ResponseBody
	public Object test(HttpServletRequest request){
		
		System.out.println("this is a test");
		return "this is a test";	
		
	}
}
